package com.wuhongyu.controller;

import com.wuhongyu.entity.Runoff;
import com.wuhongyu.service.RunoffService;
import com.wuhongyu.util.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 客户流失
 */
@Controller
@RequestMapping("/runoff")
public class RunoffController {

    @Autowired
    private RunoffService runoffService;

    @RequestMapping("/list")
    public String list(Model model, HttpServletRequest request, Runoff runoff, Integer number) {
        model.addAttribute("url",MyUtil.getUrl(request));
        model.addAttribute("page",runoffService.findAll(runoff,number));
        return "~cust/lost/list";
    }

    /**
     * 暂缓流失
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/defer")
    public String defer(Model model, Integer id){
        model.addAttribute("runoff",runoffService.findOne(id));
        return "~cust/lost/relay";
    }

    /**
     * 确认流失
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/confirm")
    public String confirm(Model model, Integer id){
        model.addAttribute("runoff",runoffService.findOne(id));
        return "~cust/lost/confirm";
    }

    @RequestMapping("/save")
    public String save(Runoff runoff) {
        runoffService.save(runoff);
        return "redirect:/runoff/list";
    }

}